using System;
using System.Data.Linq.Mapping;
using CoreLibrary.Date;

namespace Entities.DataBase.Persistent {

    [Table(Name="D_PRODUCT_CATALOG")]
    public class ProductCatalog {

        public ProductCatalog() {
            Enabled = true;
            Description = string.Empty;
            Keywords    = string.Empty;
            Thumbs      = string.Empty;
            DateCreated = DateTime.UtcNow;
            DateUpdated = DateUtil.Epoch;
        }

        /// <summary>
        /// 1. Unique ID for Product Catalog
        /// </summary>
        [Column(Name = "ID", IsPrimaryKey = true, IsDbGenerated = true)]
        public int Id { get; set; }

        /// <summary>
        /// 2. Parent Catalog ID
        /// </summary>
        [Column(Name = "PID")]
        public int PID { get; set; }

        /// <summary>
        /// 3. Left ID
        /// </summary>
        [Column(Name = "LID")]
        public int LID { get; set; }

        /// <summary>
        /// 4. Right ID
        /// </summary>
        [Column(Name = "RID")]
        public int RID { get; set; }

        /// <summary>
        /// 5. LEVEL
        /// </summary>
        [Column(Name = "LEVEL")]
        public int Level { get; set; }

        /// <summary>
        /// 6. Product Catalog English Name
        /// </summary>
        [Column(Name = "NAME")]
        public string Name { get; set; }

        /// <summary>
        /// 7. Product Catalog Chinese Name
        /// </summary>
        [Column(Name = "C_NAME")]
        public string Cname { get; set; }

        /// <summary>
        /// 8. Product Catalog Description
        /// </summary>
        [Column(Name = "DESCRIPTION")]
        public string Description { get; set; }


        /// <summary>
        /// 9. Product Catalog Keywords for search
        /// </summary>
        [Column(Name = "KEYWORDS")]
        public string Keywords { get; set; }

        /// <summary>
        /// 10. Product Catalog Thumb Collectioin
        /// </summary>
        [Column(Name = "THUMBS")]
        public string Thumbs { get; set; }

        /// <summary>
        /// 11. Determin this Catalog is enabled or not
        /// </summary>
        [Column(Name = "ENABLED")]
        public bool Enabled { get; set; }

        /// <summary>
        /// 12. Additional order for ordering
        /// </summary>
        [Column(Name = "LIST_ORDER")]
        public int ListOrder { get; set; }

        /// <summary>
        /// 13. Date This Catalog Created
        /// </summary>
        [Column(Name = "DATE_CREATED")]
        public DateTime DateCreated { get; set; }

        /// <summary>
        /// 14. Date This Catalog Updated.
        /// </summary>
        [Column(Name = "DATE_UPDATED")]
        public DateTime DateUpdated { get; set; }

        public bool IsRoot {
            get {
                return PID == 0;
            }
        }

        public bool IsLeaf {
            get {
                return RID == LID + 1;
            }
        }
    }
}